package com.zelma.consumer.service.impl;

import com.zelma.common.utils.R;
import com.zelma.consumer.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.zelma.consumer.dao.SignDao;
import com.zelma.consumer.entity.SignEntity;
import com.zelma.consumer.service.SignService;

import java.util.List;


@Service("signService")
@SuppressWarnings("all")
public class SignServiceImpl extends ServiceImpl<SignDao, SignEntity> implements SignService {
    @Autowired
    private SignDao signDao;

    @Override
    public R Enlist(UserEntity byId, List<SignEntity> signEntity, Integer groupbuyId) {

//        获取本团购表的报名数据
        List<SignEntity> bygroupbuyList = signDao.getBygroupbuyId(groupbuyId);

//        判断报名表中是否有本用户
//        不可以重复报名
        SignEntity byuserId = signDao.isByuserId(groupbuyId,byId.getUserId());
        if (byuserId!=null){
            return R.error().put("msg","不可以重复报名");
        }
//        当所有条件完成后
        SignEntity signEntity1 = new SignEntity();
        signEntity1.setUserId(byId.getUserId());
        signEntity1.setGroupbuyId(groupbuyId);
        signEntity1.setUserName(byId.getUserName());
        signEntity1.setUserTel(byId.getUserTel());
        baseMapper.insert(signEntity1);
        return R.ok().put("msg","报名成功");
    }
}